package com.example.concurrent.ScheduledExecutorService;

import java.util.concurrent.*;

/**
 * Created by Administrator on 2017/2/10 0010.
 */
public class CallableDemo {

    public static void main(String[] args) {

        ScheduledExecutorService scheduledExecutorService =
                Executors.newScheduledThreadPool(5);

        ScheduledFuture scheduledFuture =
                scheduledExecutorService.schedule(new Callable() {
                                                      public Object call() throws Exception {
                                                          System.out.println("Executed!");
                                                          return "Called!";
                                                      }
                                                  },
                        5,
                        TimeUnit.SECONDS);


        try {
            System.out.println("result = " + scheduledFuture.get());
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }

        scheduledExecutorService.shutdown();      }
}
